package cn.sirun.com.fca.personal.center.repo;

import com.tencent.cloud.iov.kernel.constant.ApiConst;
import com.tencent.cloud.iov.kernel.model.BaseResponse;
import com.tencent.cloud.iov.kernel.service.ServiceGenerator;
import com.tencent.cloud.iov.kernel.service.interceptor.ExceptionTransformer;

import java.util.List;

import cn.sirun.com.fca.account.model.base.CaptchaRequest;
import cn.sirun.com.fca.account.model.base.CarData;
import cn.sirun.com.fca.account.model.base.CarInfoDetailRequest;
import cn.sirun.com.fca.account.model.base.CarInfoDetailResponse;
import cn.sirun.com.fca.account.model.base.SubmitPhoneRequest;
import cn.sirun.com.fca.account.model.base.SubmitPhoneResponse;
import cn.sirun.com.fca.account.model.login.LoginResponse;
import cn.sirun.com.fca.account.model.login.PersonalInfo;
import cn.sirun.com.fca.account.model.login.PersonalInfoRequest;
import cn.sirun.com.fca.account.model.register.RegisterSubmitResponse;
import cn.sirun.com.fca.account.model.register.SubmitEmailRequest;
import cn.sirun.com.fca.personal.center.model.bean.CarListResponse;
import cn.sirun.com.fca.personal.center.model.request.ChangeAccountResendRequest;
import cn.sirun.com.fca.personal.center.model.request.DistributorRequest;
import cn.sirun.com.fca.personal.center.model.request.EditResellerRequest;
import cn.sirun.com.fca.personal.center.model.request.IdentityNumberRequest;
import cn.sirun.com.fca.personal.center.model.request.SubmitEmergencyInfoRequest;
import cn.sirun.com.fca.personal.center.model.request.SubmitPhonePinRequest;
import cn.sirun.com.fca.personal.center.model.request.SubmitPlateNumberRequest;
import cn.sirun.com.fca.personal.center.model.request.SubmitUnbindCarRequest;
import cn.sirun.com.fca.personal.center.model.response.CityResponse;
import cn.sirun.com.fca.personal.center.model.response.DistributorResponse;
import cn.sirun.com.fca.personal.center.model.response.SubmitCodeResponse;
import io.reactivex.Observable;

/**
 * @author vinsonhuang
 * @date 2018/7/31
 */
public class ProfileRepository {

    private static volatile ProfileRepository sInstance;

    public static ProfileRepository getInstance() {
        if (sInstance == null) {
            synchronized (ProfileRepository.class) {
                if (sInstance == null) {
                    sInstance = new ProfileRepository();
                }
            }
        }

        return sInstance;
    }

    private final ProfileService mProfileService;

    private ProfileRepository() {
        mProfileService = ServiceGenerator.createService(ProfileService.class, ApiConst
                .getBaseUrl());
    }

    public Observable<BaseResponse<PersonalInfo>> getPersonalInfo(PersonalInfoRequest request) {
        return mProfileService.getPersonalInfo(request);
    }

    public Observable<BaseResponse<Void>> submitEmergencyInfo(
            SubmitEmergencyInfoRequest request) {
        return mProfileService.submitEmergencyInfo(request);
    }

    public Observable<BaseResponse<Void>> submitIdentityNumber(
            IdentityNumberRequest request) {
        return mProfileService.submitIdentityNumber(request);
    }

    public Observable<BaseResponse<SubmitPhoneResponse>> changeAccountPhone(SubmitPhoneRequest request) {
        return mProfileService.changeAccountPhone(request)
                .compose(new ExceptionTransformer<SubmitPhoneResponse>());
    }

    public Observable<BaseResponse<SubmitPhoneResponse>> changeAccountEmail(SubmitEmailRequest request) {
        return mProfileService.changeAccountEmail(request)
                .compose(new ExceptionTransformer<SubmitPhoneResponse>());
    }

    public Observable<BaseResponse<SubmitPhoneResponse>> changeAccountResend(ChangeAccountResendRequest request) {
        return mProfileService.changeAccountResend(request)
                .compose(new ExceptionTransformer<SubmitPhoneResponse>());
    }

    public Observable<BaseResponse<RegisterSubmitResponse>> changeAccountSubmitCaptcha(String code) {
        return mProfileService.changeAccountSubmitCaptcha(new CaptchaRequest(code))
                .compose(new ExceptionTransformer<RegisterSubmitResponse>());
    }

    public Observable<BaseResponse<SubmitPhoneResponse>> bindAccountResend() {
        return mProfileService.bindAccountResend()
                .compose(new ExceptionTransformer<SubmitPhoneResponse>());
    }

    public Observable<BaseResponse<RegisterSubmitResponse>> submitBindAccountCaptcha(String code) {
        return mProfileService.submitbindAccountCaptcha(new CaptchaRequest(code))
                .compose(new ExceptionTransformer<RegisterSubmitResponse>());
    }

    public Observable<BaseResponse<SubmitPhoneResponse>> submitBindAccount(ChangeAccountResendRequest request) {
        return mProfileService.submitBindAccount(request)
                .compose(new ExceptionTransformer<SubmitPhoneResponse>());
    }

    public Observable<BaseResponse<List<CityResponse>>> getAllCity() {
        return mProfileService.getAllCity()
                .compose(new ExceptionTransformer<List<CityResponse>>());
    }

    public Observable<BaseResponse<List<DistributorResponse>>> getCityDistributor(DistributorRequest request) {
        return mProfileService.getCityDistributor(request)
                .compose(new ExceptionTransformer<List<DistributorResponse>>());
    }

    public Observable<BaseResponse<Void>> editReseller(EditResellerRequest request) {
        return mProfileService.editReseller(request)
                .compose(new ExceptionTransformer<Void>());
    }


    public Observable<BaseResponse<SubmitPhoneResponse>> submitPhonePinCaptcha(SubmitPhoneRequest request) {
        return mProfileService.submitPhonePinCaptcha(request)
                .compose(new ExceptionTransformer<SubmitPhoneResponse>());
    }

    public Observable<BaseResponse<SubmitCodeResponse>> submitVerifyCaptcha(String code) {
        return mProfileService.submitVerifyCaptcha(new CaptchaRequest(code))
                .compose(new ExceptionTransformer<SubmitCodeResponse>());
    }

    public Observable<BaseResponse<CarInfoDetailResponse>> getCarInfoDetail(String din) {
        return mProfileService.getCarInfoDetail(new CarInfoDetailRequest(din))
                .compose(new ExceptionTransformer<CarInfoDetailResponse>());
    }

    public Observable<BaseResponse<CarListResponse>> getCarList() {
        return mProfileService.getCarList()
                .compose(new ExceptionTransformer<CarListResponse>());
    }

    public Observable<BaseResponse<Void>> setCurrentVehicle(String din) {
        return mProfileService.setCurrentVehicle(new CarInfoDetailRequest(din))
                .compose(new ExceptionTransformer<Void>());
    }

    public Observable<BaseResponse<Void>> editCarNumber(SubmitPlateNumberRequest request) {
        return mProfileService.editCarNumber(request)
                .compose(new ExceptionTransformer<Void>());
    }

    public Observable<BaseResponse<Void>> unBindCar(SubmitUnbindCarRequest request) {
        return mProfileService.unBindCar(request)
                .compose(new ExceptionTransformer<Void>());
    }
}
